package think.in.java.concurrency.practise.exec8.ForNotify;

import com.sun.deploy.net.proxy.StaticProxyManager;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * Created by IntelliJ IDEA.
 * User: Richard
 * Date: 6/18/11
 * Time: 12:09 AM
 * To change this template use File | Settings | File Templates.
 */
public class Customer {

    public Customer(){
        this.setCustomerNum(customerCount.incrementAndGet());
    }
    public int getCustomerNum() {
        return customerNum;
    }

    public void setCustomerNum(int customerNum) {
        this.customerNum = customerNum;
    }

    public static  enum  Status {eating,waitingForFood,waitingForService , waitingForDeliver};
    public static AtomicInteger customerCount = new AtomicInteger(0);
    private int customerNum = 0;
    private ReentrantReadWriteLock reentrantReadWriteLock = new ReentrantReadWriteLock();
    private Status status = Status.waitingForService ;

     public Status getStatus() {
         try{
            reentrantReadWriteLock.readLock().lock();
          return status;
        }
        finally {
           reentrantReadWriteLock.readLock().unlock();
        }
    }

    public void setStatus(Status status) {
        try{
            reentrantReadWriteLock.writeLock().lock();
            this.status = status;
        }
        finally {
            reentrantReadWriteLock.writeLock().unlock();
        }
    }

    public String toString(){
         return "customer : "+this.getCustomerNum();
    }




}
